﻿using System.Collections.Generic;
using System.Linq;

namespace TAS.XtOM.Tutorial.Web.Models.LinkedIn
{
	public class LIPerson : TAS.XtOM.XmlMappedObject
	{
		private List<LIPosition> positions = new List<LIPosition>();
		private List<LIEducation> educations = new List<LIEducation>();
		private List<LIRecommendation> recommendations = new List<LIRecommendation>();
		private List<LIMemberUrl> memberUrls = new List<LIMemberUrl>();
		private List<LIPhoneNumber> phoneNumbers = new List<LIPhoneNumber>();

		[MapperInstructions("/person/id")]
		public string Id { get; set; }
		[MapperInstructions("/person/first-name")]
		public string GivenName { get; set; }
		[MapperInstructions("/person/last-name")]
		public string FamilyName { get; set; }
		[MapperInstructions("/person/specialties")]
		public string Specialties { get; set; }
		[MapperInstructions("/person/picture-url")]
		public string ImageUrl { get; set; }
		[MapperInstructions("/person/industry")]
		public string Industry { get; set; }
		[MapperInstructions("/person/num-connections", ConvertTo=typeof(int), TypeConvertionEnabled=true)]
		public int NumberOfConnections { get; set; }
		[MapperInstructions("/person/interests")]
		public string Interests { get; set; }
		[MapperInstructions("/person/date-of-birth/year")]
		public string BirthYear { get; set; }
		[MapperInstructions("/person/date-of-birth/month")]
		public string BirthMonth { get; set; }
		[MapperInstructions("/person/date-of-birth/day")]
		public string BirthDay { get; set; }
		[MapperInstructions("/person/main-address")]
		public string MainAddress { get; set; }
		[MapperInstructions("/person/headline")]
		public string Headline { get; set; }
		[MapperInstructions("/person/location/name")]
		public string LocationName { get; set; }
		[MapperInstructions("/person/location/country/code")]
		public string CountryCode { get; set; }

		[MapperInstructions("/person/positions", NodeType = NodeType.NodeList, NodeListType = typeof(LIPosition))]
		public List<LIPosition> Positions
		{
			get
			{
				return positions;
			}
		}

		[MapperInstructions("/person/educations", NodeType = NodeType.NodeList, NodeListType = typeof(LIEducation))]
		public List<LIEducation> Educations
		{
			get
			{
				return educations;
			}
		}

		[MapperInstructions("/person/recommendations-received", NodeType = NodeType.NodeList, NodeListType = typeof(LIRecommendation))]
		public List<LIRecommendation> Recommendations
		{
			get
			{
				return recommendations;
			}
		}

		[MapperInstructions("/person/member-url-resources", NodeType = NodeType.NodeList, NodeListType = typeof(LIMemberUrl))]
		public List<LIMemberUrl> MemberUrls
		{
			get
			{
				return memberUrls;
			}
		}

		[MapperInstructions("/person/phone-numbers", NodeType = NodeType.NodeList, NodeListType = typeof(LIPhoneNumber))]
		public List<LIPhoneNumber> PhoneNumbers
		{
			get
			{
				return phoneNumbers;
			}
		}

		public string MobilePhone
		{
			get
			{
				LIPhoneNumber number = PhoneNumbers.Where(p => p.PhoneType == "mobile").FirstOrDefault();
				if (number != null)
					return number.PhoneNumber;
				return null;
			}
		}

		public string WorkPhone
		{
			get
			{
				LIPhoneNumber number = PhoneNumbers.Where(p => p.PhoneType == "work").FirstOrDefault();
				if (number != null)
					return number.PhoneNumber;
				return null;
			}
		}
	}
}
